package com.yesep.learn.design.behavioral.command;

public class FanOnCommand implements ICommand {
    private final IDevice device;
    private int previousTemperature;

    public FanOnCommand(IDevice device) {
        this.device = device;
    }

    @Override
    public void execute() {
        previousTemperature = ((Fan) device).getTemperature();
        ((Fan) device).setTemperature(25); // 设定温度
        device.turnOn();
    }

    @Override
    public void undo() {
        ((Fan) device).setTemperature(previousTemperature);
        device.turnOff();
    }
}